<template>
  <div>
    <el-container>
      <el-header class="header">
        <div>
          <logo></logo>
        </div>
      </el-header>

      <el-row class="main-bg">
        <el-col :span="15" class="slide-bg">
          <img
            src="https://element.eleme.io/static/theme-index-blue.c38b733.png"
            alt="图片"
          />
        </el-col>
        <el-col :span="8" class="login-table-bg">
          <el-main class="login-table">
            <div class="table-title">账号密码登录</div>
            <el-input
              ref="account"
              class="table-margin table-shadow-border"
              v-model="account"
              placeholder="请输入账号"
              suffix-icon="el-icon-user"
              prefix="账号"
            ></el-input>
            <el-input
              ref="password"
              class="table-margin table-shadow-border"
              placeholder="请输入密码"
              v-model="password"
              suffix-icon="el-icon-view"
              show-password
            ></el-input>
            <el-button @click="login" type="primary" class="table-margin"
              >登录</el-button
            >
            <div class="table-link table-margin">
              <el-link @click="register" type="primary">免费注册</el-link>
            </div>
          </el-main>
        </el-col>
      </el-row>
    </el-container>
    <footer class="login-footer"></footer>
  </div>
</template>

<script>
import Logo from "@/components/Logo";
export default {
  components: {
    Logo,
  },
  methods: {
    register() {
      this.$router.push("/register");
    },
    login() {
      if (this.account == "") {
        this.$refs.account.focus();
        return;
      }
      if (this.password == "") {
        this.$refs.password.focus();
        return;
      }

      this.axios({
        method: "post",
        url: "http://47.99.124.245:8082/Enlogin",
        data: {
          account: this.account,
          password: this.password,
        },
      }).then((res) => {
        console.log(res)
        let code = res.data.code
        let data = res.data.data
        for(let i in data){
          if(!data[i].area){
            data.splice(i,1)
          }
        }
        if(code==200){
          //这里应该要返回一个propertyId
          this.$store.commit('setPropertys',data)
          this.$store.commit('setAccount',this.account)
          this.$router.push("home")
          this.$message.success("登录成功")
        }else{
          this.$message.error("登录失败")
        }
      }).catch(err=>{
         this.$message.error("登录失败")
      })
    },
  },
  data() {
    return {
      propertyIndexs:[],
      account: "",
      password: "",
    };
  },
};
</script>

<style scoped>
* {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}

/*header样式*/
.header {
  margin-top: 1rem;
  margin-bottom: 1rem;
}
.header div {
  margin-top: 1rem;
  margin-left: 1rem;
}

/*背景样式*/
.slide-bg {
  display: flex;
  justify-content: center;
}
.slide-bg img {
  width: 70%;
  height: auto;
}

.main-bg {
  display: flex;
}

/*表单样式 */
.login-table {
  max-height: 400px;
}
.login-table-bg {
  margin-right: 1rem;
  min-height: 30vh;
  max-height: 400px;
  background-color: rgb(217, 236, 255);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
  position: relative;
}
.login-table-bg::after {
  content: "";
  position: absolute;
  width: 50px;
  height: 50px;
  right: 0;
  top: 0;
  background: linear-gradient(to bottom left, white 50%, rgb(157, 206, 255) 0);
}
.table-title {
  color: black;
  font-weight: bold;
  margin-left: 10px;
  margin-bottom: 20px;
}

/* 输入框、按钮样式 */
.table-margin {
  margin-top: 1rem;
}
button.table-margin {
  width: 100%;
}

/* 链接样式 */
.table-link {
  display: flex;
  justify-content: flex-end;
}
.table-link a {
  margin: 0px 1rem;
}

/*footer样式*/
.login-footer {
  position: fixed;
  bottom: 0;
  margin-top: 1rem;
  background: linear-gradient(to top, rgb(63, 133, 237), rgb(87, 171, 255));
  width: 100%;
  height: 40px;
}
</style>